package com.lbmb.mdps.workbench.controller;

import com.lbmb.mdps.commons.constant.Constant;
import com.lbmb.mdps.commons.domain.DeliverReceive;
import com.lbmb.mdps.commons.domain.DeliverVo;
import com.lbmb.mdps.commons.domain.ReturnObjectVO;
import com.lbmb.mdps.commons.domain.UserReceive;
import com.lbmb.mdps.commons.exception.DeliverException;
import com.lbmb.mdps.workbench.service.DeliverService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 林文塨
 * @date 2022-05-30 23:11
 * description
 */
@CrossOrigin
@RestController
public class DeliverController {

    @Resource
    private DeliverService deliverService;

    @PostMapping( "/workbench/deliver/deliverPageList.do")
    public ReturnObjectVO deliverPageList(@RequestBody DeliverReceive deliverReceive) throws DeliverException {
        /*
         * 分页获取列表
         * @author 林文塨
         * @date 2022/5/30 23:15
         * @param [deliverReceive]
         * @return com.lbmb.mdps.commons.domain.ReturnObjectVO
         */
        ReturnObjectVO rov = new ReturnObjectVO();

        deliverReceive.setSkipCount((deliverReceive.getPageNo()-1)*deliverReceive.getPageSize());

        List<DeliverVo> deliverVoList = deliverService.deliverPageList(deliverReceive);

        rov.setOthers(deliverVoList);
        rov.setCode(Constant.RETURN_OBJECT_CODE_SUCCESS);

        return rov;
    }

    @PostMapping( "/workbench/deliver/getDeliverTotal.do")
    public ReturnObjectVO getDeliverTotal(@RequestBody DeliverReceive deliverReceive) throws DeliverException {
        /*
         * 获取分页总条数功能
         * @author 林文塨
         * @date 2022/5/30 10:38
         * @param [employeeReceive]
         * @return com.lbmb.mdps.commons.domain.ReturnObjectVO
         */
        ReturnObjectVO rov = new ReturnObjectVO();

        Integer total = deliverService.getDeliverTotal(deliverReceive);
        rov.setNumber(total);
        rov.setCode(Constant.RETURN_OBJECT_CODE_SUCCESS);

        return rov;
    }

    @PostMapping( "/workbench/deliver/editOrderState.do")
    public ReturnObjectVO editOrderState(@RequestBody UserReceive userReceive) throws DeliverException {
        /*
         * 改变订单状态
         * @author 林文塨
         * @date 2022/5/30 16:17
         * @param [employee]
         * @return com.lbmb.mdps.commons.domain.ReturnObjectVO
         */
        ReturnObjectVO rov = new ReturnObjectVO();

        deliverService.editOrderState(userReceive);
        rov.setCode(Constant.RETURN_OBJECT_CODE_SUCCESS);

        return rov;
    }

}
